<?php

	// TITLE: Home_owner_group AUTO MODEL
	// FILE: scaffolding/model/home_owner_group.php
	// AUTHOR: AUTOGEN
	// CREATED: 2015/04/20 07:49:57
	// DESCRIPTION: 
	// REQUIREMENTS: 

	$createHomeOwnerGroup = function($con, $homeOwnerGroup) {
		$sql = 'INSERT INTO home_owner_group (person_id, home_owner_id, date, driver_license_id) VALUES (';
		$sql .= $home_owner_group->getPersonId() . ', ';
		$sql .= $home_owner_group->getHomeOwnerId() . ', ';
		$sql .= $home_owner_group->getDate() . ', ';
		$sql .= $home_owner_group->getDriverLicenseId() . ')';
		$sql .= ')';
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		mysqli_close($con);
		return $id;
	};

	$readHomeOwnerGroup = function($con, $id) {
		$sql = 'SELECT * FROM home_owner_group WHERE id = ' . $id;
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$result = mysqli_fetch_array($results);
			$homeOwnerGroup = new HomeOwnerGroup();
			$homeOwnerGroup->setPersonId($dbio->select($readPerson(result[0])));
			$homeOwnerGroup->setHomeOwnerId($dbio->select($readHomeOwner(result[1])));
			$homeOwnerGroup->setDate(result[2]);
			$homeOwnerGroup->setDriverLicenseId($dbio->select($readDriverLicense(result[3])));
		} else {
			$homeOwnerGroup = false;
		}
		return $homeOwnerGroup;
	};

	$updateHomeOwnerGroup = function($con, $homeOwnerGroup) {
		$sql = 'UPDATE home_owner_group SET ';
		$sql .= 'person_id = ' . $home_owner_group->getPersonId() . ', ';
		$sql .= 'home_owner_id = ' . $home_owner_group->getHomeOwnerId() . ', ';
		$sql .= 'date = ' . $home_owner_group->getDate() . ', ';
		$sql .= 'driver_license_id = ' . $home_owner_group->getDriverLicenseId() ;
		$sql .= 'WHERE id = ' . id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$deleteHomeOwnerGroup = function($con, $id) {
		$sql = 'DELETE FROM home_owner_group WHERE person_id = ' . $id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$listHomeOwnerGroup = function($con) {
		$sql = 'SELECT * FROM home_owner_group';
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$homeOwnerGroups = array();
			while ($result = mysqli_fetch_array($results)) {
				$homeOwnerGroup = new HomeOwnerGroup();
				$homeOwnerGroup->setPersonId($dbio->select($readPerson(result[0])));
				$homeOwnerGroup->setHomeOwnerId($dbio->select($readHomeOwner(result[1])));
				$homeOwnerGroup->setDate(result[2]);
				$homeOwnerGroup->setDriverLicenseId($dbio->select($readDriverLicense(result[3])));
				$homeOwnerGroups[] = homeOwnerGroup;
			}// end while
		} else {
			$homeOwnerGroups = false;
		}
		return $homeOwnerGroups;
	};

